package Eyjafjalla.action;

import Eyjafjalla.blight.DreamKey;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.blights.AbstractBlight;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;

public class DreamKeyAction extends AbstractGameAction {

    AbstractCard remove;

    public DreamKeyAction(AbstractCard removed){
        startDuration = duration = Settings.ACTION_DUR_XFAST;
        this.remove = removed;
    }

    @Override
    public void update() {
        if(startDuration==duration){
            CardCrawlGame.sound.playA("KEY_OBTAIN", -0.2F);
            if(!AbstractDungeon.player.hasBlight(DreamKey.ID))
                AbstractDungeon.getCurrRoom().spawnBlightAndObtain(Settings.WIDTH/2F,Settings.HEIGHT/2F,new DreamKey());
            AbstractCard re = null;
            for(AbstractCard c:AbstractDungeon.player.masterDeck.group){
                if(c.cardID.equals(remove.cardID)){
                    re = c;
                    break;
                }
            }
            if(re!=null){
                AbstractDungeon.player.masterDeck.removeCard(re);
            }
        }

        this.tickDuration();
    }
}
